package com.xmkj.winmoney.home;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.bumptech.glide.Glide;
import com.bumptech.glide.Priority;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.common.banner.Holder;
import com.xmkj.winmoney.R;


public class NetworkImageHolderView implements Holder<String> {

    private ImageView imageView;

    @Override
    public View createView(Context context) {
        imageView = new ImageView(context);
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);

   /*     RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(imageView.getLayoutParams());
        lp.setMargins(20, 20, 20, 20);
        imageView.setLayoutParams(lp);*/
       /* setMargins(imageView,20,20,20,20);
       ViewGroup.LayoutParams params = imageView.getLayoutParams();
        params.height=200;
        imageView.setLayoutParams(params);*/
 
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(100, 100);
        params.setMargins(5, 5, 5, 5);



        return imageView;
    }
    public static void setMargins (View v, int l, int t, int r, int b) {
        if (v.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
            ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
            p.setMargins(l, t, r, b);
            v.requestLayout();
        }
    }

    @Override
    public void UpdateUI(Context context, int position, String data) {

     /*   Glide.with(context)
                .load(data)
                .thumbnail(0.2f)
                .placeholder(R.drawable.blank_pic)
                .into(imageView);*/

        RequestOptions options = new RequestOptions()
                .centerCrop()
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .placeholder(R.mipmap.blank_pic)
                .error(R.mipmap.blank_pic)
                .priority(Priority.HIGH);
        Glide.with(imageView.getContext()).load(data).apply(options).into(imageView);
    }
}
